import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xvideos/hj_page/home_business/section_all_page/section_all_logic.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';
import 'package:xvideos/tools_base/appbar/base_app_bar.dart';
import 'package:xvideos/tools_base/loading/l_error_widget.dart';
import 'package:xvideos/tools_base/loading/loading_center_widget.dart';
import 'package:xvideos/tools_base/refresh/pull_refresh.dart';
import 'package:xvideos/tools_base/widget/net_image_widget.dart';

import '../../../hj_model/home/module_detail_model.dart';
import '../special_topic_detail/specail_topics_detail_page.dart';

class SectionAllPage extends StatelessWidget {
  final String id;

  const SectionAllPage(this.id, {super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: SectionAllLogic(id),
      builder: (logic) => Scaffold(
        appBar: BaseAppBar(title: "网黄女优"),
        body: () {
          if (logic.dataSource == null) {
            return LoadingCenterWidget();
          } else if (logic.dataSource!.isEmpty) {
            return CErrorWidget(
              retryOnTap: () => logic.onInitData(),
            );
          } else {
            return pullYsRefresh(
              onInit: (ctr) => logic.refreshController = ctr,
              onRefresh: (ctr) => logic.refreshData(),
              onLoading: (ctr) => logic.loadMoreData(),
              child: ListView.builder(
                padding: EdgeInsets.fromLTRB(16, 12, 16, 0),
                itemCount: logic.dataSource?.length ?? 0,
                itemBuilder: (context, index) {
                  AllSection model = logic.dataSource![index];
                  return InkWell(
                    onTap: (){
                      Get.to(SpecailTopicsDetailPage(model), preventDuplicates: false);
                    },
                    child: Container(
                      margin: EdgeInsets.only(bottom: 12),
                      height: 50,
                      child: Row(
                        children: [
                          NetworkImageLoader(
                            imageUrl: model.sectionCover,
                            width: 50,
                            height: 50,
                            borderRadius: 50,
                          ),
                          12.sizeBoxW,
                          Expanded(
                            child: Text(
                              model.sectionName ?? "",
                              maxLines: 1,
                              style: TextStyle(
                                color: Color(0xffFFFFFF),
                                fontSize: 16,
                                fontWeight: FontWeight.w500,
                              ),
                            ),
                          ),
                          12.sizeBoxW,
                          Icon(Icons.keyboard_arrow_right, color: Colors.white, size: 16),
                        ],
                      ),
                    ),
                  );
                },
              ),
            );
          }
        }(),
      ),
    );
  }
}
